#include <app\states\viewingParametersState.h>
#include <app\states\statesFactory.h>

int viewingParametersState::class_type_id = VIEWING_PARAMETERS_STATE_TYPE_ID;

REGISTER_STATE(VIEWING_PARAMETERS_STATE_TYPE_ID, viewingParametersState);

sessionState *
viewingParametersState::create() {
  return new viewingParametersState();
} 

void 
viewingParametersState::copy(const viewingParametersState *vp_state) {
  info = vp_state->info;
}

void 
viewingParametersState::addViewChangeObserver(viewChangeObserver *ref) {
  viewChange_sig.connect(boost::bind(&viewChangeObserver::viewChange, ref, _1));
}

void 
viewingParametersState::setWindowSize(int width, int height) {

  if (width > height) height = width;
  else width = height;

  info.window_size = vec2i(width, height);
  
  modelInfoState *model_info = GET_STATE(modelInfoState, streamingClient::instance().connection());
  info.tiled_window_size = info.tiled_window_size = info.window_size / model_info->info().tex_tile_size;

  viewChange_sig(this);
}

void
viewingParametersState::setLevelsInterval(int from, int to) {

  info.level_interval = vec2i(from, to);

  viewChange_sig(this);
}

int 
viewingParametersState::getClassTypeId() {
  return viewingParametersState::class_type_id;
}

int 
viewingParametersState::getTypeId() {
  return type_id;
}

viewingParametersState::viewingParametersState() : type_id(VIEWING_PARAMETERS_STATE_TYPE_ID) {
  changed = false;
}

viewingParametersState::~viewingParametersState() {

}